package com.xz.knowledgeDuplication.pattern.responsibility;

/**
 * 抽象处理者角色
 *
 * @author 召
 * @date 2022-03-24 21:42:57
 */
public abstract class Handler {

    protected static final int NUM_ONE = 1;

    protected static final int NUM_THREE = 3;

    protected static final int NUM_SEVEN = 7;

    private int numStart;

    private int numEnd;

    private Handler nextHandler;

    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    /**
     * 提交请假
     * @param leave 请假
     */
    public void submit(LeaveRequest leave) {
        if (0 == this.numStart) {
            return;
        }
        // 请假天数带到该领导处理要求
        if (leave.getNum() >= this.numStart) {
            this.handleLeave(leave);
            // 如果还有上级 并且请假天数超过了当前领导的处理范围
            if (null != this.nextHandler && leave.getNum() > numEnd) {
                this.nextHandler.submit(leave);
            } else {
                System.out.println("流程结束");
            }
        }

    }

    /**
     *
     * 各级领导处理请假方法
     *
     * @param leave 请假
     */
    protected abstract void handleLeave(LeaveRequest leave);
}
